package com.lab.utils;

/**
 * Created by ak
 */
public interface Destroyable {
    /**
     * 主动清理对象引用，减少GC
     *
     * @param focus 是否强制清理
     */
    public abstract void destroyObject(boolean focus);

    /**
     * 是否清理成功
     */
    public abstract boolean isDestroyed();

    /**
     * 设置状态
     */
    public abstract void setState(DestroyableObjectState state);

    /**
     * Destroyable对象状态枚举
     * NONE(1)＝未初始化
     * INIT(2)＝初始化
     * DESTROYING(3)＝清理中
     * DESTROYED(4);＝清理完成
     * <p/>
     * 一般流程 NONE->INIT->DESTROYING->DESTROYED
     * 复制流程（即单次清理未完全释放）NONE->INIT->DESTROYING->...->INIT->DESTROYING->DESTROYED
     */
    public enum DestroyableObjectState {
        NONE(1),
        INIT(2),
        DESTROYING(3),
        DESTROYED(4);
        private int id;

        DestroyableObjectState(int id) {
            this.id = id;
        }

        public int getId() {
            return id;
        }
    }
}
